<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * 
 * @author chuck
 */

class AccessFilter extends CFilter{

    // validate the signature of a request.
    protected function preFilter($fiterChain) {
    	$jsonObj = Trans::readJsonPost();
    	$this->llog(json_encode($jsonObj), "Filters.token.post");
    	if(!isset($jsonObj->token))
    	{
    		throw new CHttpException(405,'Token Empty');
    	}else{
    		if(UserService::getInstance()->isTokenExists($jsonObj->token))
    		{
    			$this->llog($jsonObj->token, "Filters.token");
    			return true;
    		}else 
    		{
    			throw new CHttpException(405,'Token invalid');
    		}
    	}
       return true;
    }
    public function llog($msg,$catename)
    {
    	if(Config::$debug)
    	{
    		Yii::log($msg,"warning", $catename);
    	}
    }
}

?>
